﻿Namespace BaseballScoreKeeper.Core
    Public Class Name
#Region "Private Members"
        Private _FirstName As String
        Private _MiddleName As String
        Private _LastName As String
        Private _Suffix As NameSuffix
#End Region

#Region "Public Methods"
#Region "Constructor(s)"
        Public Sub New()
            Me.New(String.Empty, String.Empty, String.Empty, String.Empty)
        End Sub

        Public Sub New(ByVal copy As Name)
            Me._FirstName = copy.FirstName
            Me._MiddleName = copy.MiddleName
            Me._LastName = copy.LastName
            Me._Suffix = copy.Suffix
        End Sub

        Public Sub New(ByVal firstName As String, ByVal lastName As String, Optional ByVal suffix As NameSuffix = NameSuffix.None)
            Me.New(firstName, lastName, String.Empty, suffix)
        End Sub

        Public Sub New(ByVal firstName As String, ByVal lastName As String, ByVal middleName As String,
                       Optional ByVal suffix As NameSuffix = NameSuffix.None)
            Me._FirstName = firstName
            Me._MiddleName = middleName
            Me._LastName = lastName
            Me._Suffix = suffix
        End Sub
#End Region

#Region "Overridden Methods"
        Public Overrides Function Equals(ByVal obj As Object) As Boolean
            Dim isEqual As Boolean = False

            If obj.GetType Is GetType(Name) Then
                Dim compareName As Name = DirectCast(obj, Name)

                If ((Me.FirstName = compareName.FirstName) AndAlso
                    (Me.MiddleName = compareName.MiddleName) AndAlso
                    (Me.LastName = compareName.LastName) AndAlso
                    (Me.Suffix = compareName.Suffix)) Then
                    isEqual = True
                End If
            Else
                isEqual = MyBase.Equals(obj)
            End If

            Return isEqual
        End Function

        Public Overrides Function GetHashCode() As Integer
            Return MyBase.GetHashCode()
        End Function
#End Region

#Region "Operators"
        Public Shared Operator =(ByVal name1 As Name, ByVal name2 As Name) As Boolean
            Dim areEqual As Boolean = False
            If ((name1.FirstName = name2.FirstName) AndAlso
                (name1.MiddleName = name2.MiddleName) AndAlso
                (name1.LastName = name2.LastName) AndAlso
                (name1.Suffix = name2.Suffix)) Then
                areEqual = True
            End If
            Return areEqual
        End Operator

        Public Shared Operator <>(ByVal name1 As Name, ByVal name2 As Name) As Boolean
            Return (Not (name1 = name2))
        End Operator
#End Region
#End Region

#Region "Properties"
        Public ReadOnly Property FirstName As String
            Get
                Return _FirstName
            End Get
        End Property

        Public ReadOnly Property LastName As String
            Get
                Return _LastName
            End Get
        End Property

        Public ReadOnly Property MiddleName As String
            Get
                Return _MiddleName
            End Get
        End Property

        Public ReadOnly Property Suffix As NameSuffix
            Get
                Return _Suffix
            End Get
        End Property

        Public ReadOnly Property FullName As String
            Get
                Dim suffixString As String = String.Empty
                Select Case Me.Suffix
                    Case NameSuffix.Senior
                        suffixString = "Sr."
                    Case NameSuffix.Junior
                        suffixString = "Jr."
                    Case NameSuffix.TheSecond
                        suffixString = "II"
                    Case NameSuffix.TheThird
                        suffixString = "III"
                    Case NameSuffix.TheFourth
                        suffixString = "IV"
                End Select

                Dim fullNameString As String = Me.FirstName

                If Me.MiddleName <> String.Empty Then
                    fullNameString += (" " + Me.MiddleName)
                End If

                fullNameString += (" " + Me.LastName)

                If Me.Suffix <> NameSuffix.None Then
                    fullNameString += (" " + suffixString)
                End If

                Return fullNameString
            End Get
        End Property
#End Region
    End Class
End Namespace